{extend name="common:base" /}

{block name="main"}
<!--body wrapper start-->
<div class="wrapper">
    <div class="pull-left">
        <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
    </div>
    <div class="row">
        <div class="col-md-12">
            <!--breadcrumbs start -->
            <ul class="breadcrumb panel">
                <li><a href="{:url('Index/index')}"><i class="fa fa-home"></i> 控制台</a></li>
                <li><a href="{:url('index')}">文章管理</a></li>
                <li class="active">编辑文章</li>
            </ul>
            <!--breadcrumbs end -->
        </div>
    </div>

    <div class="panel-body">
        <form method="post" action="{:url('article_edit')}" class="form-horizontal bucket-form">
            <div class="form-group">
                <label class="col-sm-1 control-label">文章标题</label>
                <div class="col-sm-11">
                 <input type="text" name="title" value="{$data.title}" size="60">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">文章类型</label>
                <div class="col-sm-11">
                    <select name="cate">
                        {foreach $cate as $k=>$v}
                          <option value="{$v['id']}"{if $v['id']==$data['cate']}selected{/if}>{$v['name']}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group ">
                <label class="col-sm-1 control-label">图片</label>
                <div class="col-sm-11">
                    <p class="bor_b left mg_tb10" id="demo3">
                        {foreach $picture as $k=>$v}
                           <img height="100px" class="first"  src="URL_IMG{$v}"/>
                        {/foreach}
                        <p style="color:green"> 图片不要传太大，不然会影响加载速度哦</p>
                       <span class="file_p text-center" id="btn_logo">
                           <img height="100px"   id="btn_logo_img" src="__IMG__/add-button.jpg"/><br />
                            {foreach $picture as $k=>$v}
                               <input type="hidden" class="second" name="picture[]" value="{$v}"/>
                            {/foreach}
                        </span>
                    </p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">文章内容</label>
                <div class="col-sm-11">
                    <textarea  id="container" name="content"  rows="10">{$data.content}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">来源</label>
                <div class="col-sm-11">
                    <input type="text" name="origin" value="{$data.origin}" >
                </div>
            </div>
            <input type="hidden" name="id" value="{$data.id}">
            <div class="form-group">
                <label class="col-sm-1 control-label"></label>
                <div class="col-lg-10 right">
                    <button class="btn btn-primary " target-form="bucket-form"  type="submit">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!--body wrapper end-->
{/block}
{block name="js"}
<!--<script src="__JS__/jquery-1.10.2.min.js"></script>-->
<script type="text/javascript" src="__JS__/UE/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__JS__/UE/ueditor.all.min.js"></script>

<script type="text/javascript" src="__JS__/UE/lang/zh-cn/zh-cn.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var editor = UE.getEditor('container',{
        serverUrl: "{:url('admin/ueditor/index')}",
        initialFrameWidth:1000,
        initialFrameHeight:800,
        autoHeightEnabled:false
    });
</script>
<script type="text/javascript" src="__JS__/Plupload/plupload.full.min.js"></script>
<script type="text/javascript">
    var ids = new Array("btn_logo");
    $.each(ids,function(i,n){


        var self = this.toString();

        var uploader_avatar = new plupload.Uploader({

            runtimes: 'gears,html5,html4,silverlight,flash', //上传插件初始化选用那种方式的优先级顺序

            browse_button: self, // 上传按钮

            url: "{:url('upload_one')}", //远程上传地址

            flash_swf_url: '__DTSC__/Moxie.swf',//flash文件地址

            silverlight_xap_url: '__DTSC__/Moxie.xap', //silverlight文件地址

            filters: {

                max_file_size: '100mb', //最大上传文件大小（格式100b, 10kb, 10mb, 1gb）

                mime_types: [//允许文件上传类型

                    {title: "files", extensions: "jpg,png,gif,jpeg"}

                ]

            },

            multi_selection: false, //true:ctrl多文件上传, false 单文件上传

            init: {

                FilesAdded: function(up, files) { //文件上传前
                    var numbers = $('.first_a').length;
                    if(numbers>=3){
                        alert('最多选择三张图片');
                        return false;
                    }

                    uploader_avatar.start();

                },

                UploadProgress: function(up, file) { //上传中，显示进度条

                    var percent = file.percent;

                    $("#" + file.id).find('.bar').css({"width": percent + "%"});

                    $("#" + file.id).find(".percent").text(percent + "%");

                },

                FileUploaded: function(up, file, info) { //文件上传成功的时候触发

                    var data = eval("(" + info.response + ")");//解析返回的json数据

                    if(data.status == 1){
                        $('.first').remove();
                        $('#demo3').append('<img class="first_a"  height="100" src="'+ data.pic +'" alt="'+ file.name +'" class="layui-upload-img">');
                        $('.second').remove();
                        $('#btn_logo').append('<input  type="hidden" name="picture[]" value="'+data.picd+'"/>');

                    }else{

                        alert(data.error);

                    }

                },

                Error: function(up, err) { //上传出错的时候触发

                    alert(err.message);

                }

            }

        });

        uploader_avatar.init();

    })







</script>
{/block}
